package com.leji.song.mainPage;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import com.dgl.sdk.view.WidgetAnim;
import com.leji.song.R;
import com.leji.song.extra.BaseActivity;
import com.leji.song.mainPage.model.DS_ShopDetail;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by colin.ding on 2014/7/18.
 */
public class SearchShopActivity extends BaseActivity {

    private EditText searchText;
    private Button searchBtn;
    private ListView shopListView;
    private List<DS_ShopDetail> shopList;
    private List<DS_ShopDetail> shopListFilt = new ArrayList<DS_ShopDetail>();
    private ShopAdapter shopadapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setAnimType(RIGHT_ENTER_LEFT_EXT);
        super.onCreate(savedInstanceState);

        setContentView(R.layout.search_shop);

        initView();

        shopList = (List<DS_ShopDetail>) getIntent().getSerializableExtra("shopList");

//        ShopAdapter adapter = new ShopAdapter(this, shopList);
//        shopListView.setAdapter(adapter);
    }

    private void initView() {

        setReturnBtn();
        setActivityTitle("商家搜索");

        searchText = (EditText) findViewById(R.id.searchText);
        searchBtn = (Button) findViewById(R.id.searchBtn);
        shopListView = (ListView) findViewById(R.id.shopListView);


        searchBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                 if(WidgetAnim.checkIfEmpty(SearchShopActivity.this, searchText)){
                     return;
                 }

                String key = searchText.getText().toString();

                shopListFilt.clear();
                for(DS_ShopDetail shopDetail: shopList){

                    if(shopDetail.getName().contains(key)){

                        shopListFilt.add(shopDetail);
                    }

                }

                if(shopListFilt.size()>0){
                    shopadapter = new ShopAdapter(SearchShopActivity.this, shopListFilt);
                    shopListView.setAdapter(shopadapter);
                }else{
                    showToast("未找到相关商家");
                }

            }
        });
    }
}
